#include <iostream>
#include <string>

#include "linked_list.h"

using namespace std;

#define NUM_ELEMS(arr) (sizeof(arr) / sizeof(arr[0]))

template <typename T>
void sortedInsert(LinkedList<T> &linkedList, T value);

int main() {
	LinkedList<int> l1;

	int randomInts[] = {23, 65, 2, 43, 12, 18};

	for (int i = 0; i < NUM_ELEMS(randomInts); i++)
		sortedInsert(l1, randomInts[i]);

	cout << "l1: " << l1 << endl;

	LinkedList<string> l2;

	string randomStrings[] = {"Cat", "Elephant", "Dog", "Buffalo", "Chimp", "Baboon"};

	for (int i = 0; i < NUM_ELEMS(randomStrings); i++)
		sortedInsert(l2, randomStrings[i]);

	cout << "l2: " << l2 << endl;

	return 0;
}

template <typename T>
void sortedInsert(LinkedList<T> &linkedList, T value) {
	
	LinkedListIterator<T> iter = linkedList.begin(), iter2 = linkedList.end();
	while (iter != linkedList.end() && value >= *iter) {
		iter2 = iter;
		++iter;
	}

	if (iter2 == linkedList.end())
		linkedList.insert(value);
	else
		linkedList.insert(value, iter2);
}	